/*
 * @lc app=leetcode.cn id=2243 lang=typescript
 *
 * [2243] 计算字符串的数字和
 */

// @lc code=start
function digitSum(s: string, k: number): string {
    while (s.length > k) {
        let item: string[] = [];
        for (let i = 0; i < s.length; i += k) {
            item.push(s.slice(i, i + k));
        }
        s = item
            .map((i) => {
                return i.split("").reduce((col, cur) => {
                    return col + parseInt(cur);
                }, 0);
            })
            .join("");
    }
    return s;
}
// @lc code=end
